﻿<RangeBase x:Class="rwpf.Input.ProgressSlider"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           MouseEnter="Slider_MouseEnter" MouseLeave="Slider_MouseLeave" MouseMove="Slider_MouseMove"
           StylusInRange="RangeBase_StylusInRange" StylusOutOfRange="RangeBase_StylusOutOfRange" StylusMove="RangeBase_StylusMove" StylusInAirMove="RangeBase_StylusInAirMove" 
        xmlns:local="clr-namespace:rwpf.Input" 
             mc:Ignorable="d" 
             d:DesignHeight="30" d:DesignWidth="300">
    <RangeBase.Resources>
        <local:PassThoughConverter x:Key="v2p" />
        <local:BrushVisibilityConverter x:Key="bv" />
        <BooleanToVisibilityConverter x:Key="b2v" />
        <local:ValueToWidthConverter x:Key="v2w" />
    </RangeBase.Resources>
    <RangeBase.Style>
        <Style TargetType="RangeBase">
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="Height" Value="20" />
        </Style>
    </RangeBase.Style>
    <RangeBase.Template>
        <ControlTemplate TargetType="RangeBase">
            <Grid Height="{TemplateBinding Height}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>
                <Grid Visibility="{Binding Path=DisplayMinButton, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}},Converter={StaticResource b2v}}">
                    <Grid Grid.Column="2" Height="{TemplateBinding Height}">
                        <Path Data="{Binding Path=MinimumButtonGeometry, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" Margin="10,5,5,5" Fill="{TemplateBinding Foreground}" Stretch="Uniform" >

                        </Path>
                    </Grid>
                    <Button Name="setToMin" Click="setToMin_Click" Opacity="0" />
                </Grid>
                <ProgressBar SnapsToDevicePixels="True" Name="valueBar" Value="{TemplateBinding Value}" Minimum="{Binding Path=Minimum, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" Maximum="{Binding Path=Maximum, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" Grid.Column="1" />
                <TextBlock Name="valueText" FontSize="{TemplateBinding FontSize}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1" Visibility="{Binding Path=DisplayValue, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}, Converter={StaticResource b2v}}" >
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource v2p}">
                            <Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}" />
                            <Binding Path="Minimum" RelativeSource="{RelativeSource TemplatedParent}" />
                            <Binding Path="Maximum" RelativeSource="{RelativeSource TemplatedParent}" />
                            <Binding Path="ValueConverter" RelativeSource="{RelativeSource AncestorType={x:Type local:ProgressSlider}}" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>

                <Grid Grid.Column="1" SnapsToDevicePixels="True" Margin="0,0,0,0" Visibility="{Binding Path=DisplayPreview, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}},Converter={StaticResource b2v}}">
                    <ProgressBar  Name="previewBar" BorderThickness="0" Grid.Column="1" Background="Transparent" Opacity="{Binding Path=CurrentPreviewOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}"  Foreground="{Binding Path=PreviewForeground, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" Value="{Binding Path=PreviewValue, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" Minimum="{Binding Path=Minimum, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" Maximum="{Binding Path=Maximum, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}"  />
                    <TextBlock TextAlignment="Center" HorizontalAlignment="Left" MinWidth="30" Grid.Column="1" Opacity="{Binding Path=CurrentPreviewOpacity, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" FontSize="{TemplateBinding FontSize}" FontWeight="Bold" VerticalAlignment="Center"  >
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource v2p}">
                                <Binding Path="PreviewValue" RelativeSource="{RelativeSource AncestorType={x:Type local:ProgressSlider}}" />
                                <Binding Path="Minimum" RelativeSource="{RelativeSource TemplatedParent}" />
                                <Binding Path="Maximum" RelativeSource="{RelativeSource TemplatedParent}" />
                                <Binding Path="ValueConverter" RelativeSource="{RelativeSource AncestorType={x:Type local:ProgressSlider}}" />
                            </MultiBinding>
                        </TextBlock.Text>
                        <TextBlock.Width>
                            <MultiBinding Converter="{StaticResource v2w}">
                                <Binding Path="Value" ElementName="previewBar" />
                                <Binding Path="Minimum" ElementName="previewBar" />
                                <Binding Path="Maximum" ElementName="previewBar" />
                                <Binding Path="ActualWidth" ElementName="previewBar" />
                            </MultiBinding>
                        </TextBlock.Width>
                    </TextBlock>
                </Grid>

                <Button Opacity="0" Name="setToValue" Click="setToValue_Click" Grid.Column="1" />

                <Grid Grid.Column="2" Visibility="{Binding Path=DisplayMaxButton, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}},Converter={StaticResource b2v}}">
                    <Grid Grid.Column="2" Height="{TemplateBinding Height}">
                        <Path Data="{Binding Path=MaximumButtonGeometry, RelativeSource={RelativeSource AncestorType={x:Type local:ProgressSlider}}}" Margin="2" Stretch="Uniform" >
                            <Path.Fill>
                                <MultiBinding Converter="{StaticResource bv}">
                                    <Binding ElementName="valueBar" Path="Value" />
                                    <Binding ElementName="valueBar" Path="Foreground" />
                                    <Binding ElementName="valueBar" Path="Maximum" />
                                    <Binding ElementName="valueText" Path="Foreground" />
                                </MultiBinding>
                            </Path.Fill>
                        </Path>
                    </Grid>
                    <Button Name="setToMax" Click="setToMax_Click" Opacity="0" Grid.Column="2" />
                </Grid>
            </Grid>
        </ControlTemplate>
    </RangeBase.Template>
</RangeBase>
